<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">[{$activity.name}]活动报名列表</h3>

        <div class="box-tools pull-right">
            <a href="javascript:;" class="btn btn-sm btn-info btn-flat pull-left" onclick="showEditModel()"><i class="fa fa-fw fa-arrow-circle-down"></i> 下载</a>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="table-responsive">
            <table class="table no-margin">
                <thead>
                    <tr>
                        <th>姓名</th>
                        <th>手机号</th>
                        <th>报名时间</th>
                        <th>当前状态</th>
                        <th>报名信息</th>
                        <th>管理操作</th>
                    </tr>
                </thead>
                <tbody>
                  
                    <tr>
                        <td width='7%'>
                            <button class="btn btn-info" onclick='setOrder("{:url('activity/setOrder')}")'>排序</button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- /.table-responsive -->
    </div>
    <!-- /.box-body -->
    <div class="box-footer text-right">
        {$list->render()}
    </div>
</div>


<div class="modal fade" id="activityModel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><span>编辑</span>活动</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="activityForm">
                    <input type="hidden"  id="activityId" name="id" value="" />
                    <div class="form-group">
                        <label for="activityTitle" class="col-sm-3 control-label">活动名称：</label>

                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="activityTitle" name="name" placeholder="活动名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="activityType" class="col-sm-3 control-label">活动类型：</label>

                        <div class="col-sm-3">
                            <select class="form-control" name="type">
                                {foreach $activityType as $key=>$value}
                                <option value="{$key}">{$value}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <!--
                    <div class="form-group">
                        <label for="activityClass" class="col-sm-3 control-label">活动类别：</label>

                        <div class="col-sm-3">
                            <select class="form-control" name="classid">
                                {foreach $activityClass as $key=>$value}
                                <option value="{$key}">{$value}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    -->
                    <div class="form-group">
                        <label for="activityStart" class="col-sm-3 control-label">活动日期：</label>

                        <div class="col-sm-3">
                            <input type="text" class="form-control datepicker" id="activityStart" placeholder="开始时间" value="" name="startdate" />
                        </div>
                        <div class="col-sm-1">
                            <label class="control-label">至</label>
                        </div>
                        <div class="col-sm-3">
                            <input type="text" class="form-control datepicker" id="activityEnd" placeholder="结束时间" name="enddate">
                        </div>
                        <div class="col-sm-2">
                            <label class="control-label text-green">可选项</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="description" class="col-sm-3 control-label">活动描述：</label>

                        <div class="col-sm-9">
                            <textarea class="form-control" rows="3" id="description" placeholder="活动描述 ..." name="description"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="img_path" class="col-sm-3 control-label">活动封面：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="img_path" name="img_path" placeholder="图片地址">
                        </div>
                        <div class="col-sm-3">
                            <button type="button" class="form-control btn btn-default btn-file" onclick="$('#activityImg').click()">选择图片</button>
                            <input type="file" class="form-control btn btn-file" id="activityImg" onchange="upActivityImg(this)" style="display: none;"/>
                        </div>

                    </div>
                    <div class="form-group">
                        <label for="list_order" class="col-sm-3 control-label">排序值：</label>

                        <div class="col-sm-3">
                            <input type="number" class="form-control" id="list_order" name="list_order" value='0' placeholder="排序值">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="activityStatus" class="col-sm-3 control-label">活动状态：</label>

                        <div class="col-sm-3">
                            <select class="form-control" id="activityStatus" name="status">
                                {foreach $activityStatus as $key=>$value}
                                <option value="{$key}">{$value}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="savePosterActivity()">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    /**
     * 显示编辑框
     * @returns {undefined}
     */
    function showEditModel() {
        fromReset('activityForm');
        $('#activityStatus').val(1);
        $("#activityModel").modal('show');
    }

    /**
     * 编辑活动
     */
    function editActivity(info) {
        showEditModel();
        $('#activityId').val(info.id);
        $('#activityTitle').val(info.name);
        $('#activityType').val(info.type);
        var statrDate = $('#row_' + info.id + ' .startdate').html();
        var endDate = $('#row_' + info.id + ' .enddate').html();
        if(statrDate != '---'){
            $('#activityStart').val(statrDate);    
        }
        if(endDate != '---'){
            $('#activityEnd').val(endDate);    
        }
        $('#description').val(info.description);
        $('#img_path').val(info.img_path);
        $('#list_order').val(info.list_order);
        $('#activityStatus').val(info.status);
    }
    
    /**
     * 上传图片
     * @param {type} fileInput
     * @returns {undefined}
     */
    function upActivityImg(fileInput) {
        var file = $(fileInput)[0].files[0];
        //console.log($(fileInput));
        ajaxFile(file, function (response) {
            console.log(response);
            if (response.code == 1) {
                $('#img_path').val(response.msg);
                //$('#posterImg').attr('src', response.msg);
            } else {
                toast('图片上传失败', response.msg, 2000);
            }
        });
    }

    /**
     * 删除活动
     */
    function delActivity(id, name) {
        var _url = '{:url("activity/delActivity")}';
        url = _url + '?id=' + id;
        confirmDelDefault(url, "活动名称：" + name + "<br/>该操作会一并删除此活动下的所有报名信息，请谨慎操作！");
    }

    /**
     * 保存内容
     * @returns {Boolean}
     */
    function savePosterActivity() {
        var formData = $('#activityForm').serializeArray();
        var data = {};
        $.each(formData, function () {
            data[this.name] = this.value;
        });
        console.log(data);
        if (!data.name) {
            toast('提示', '活动名称不能为空', 1000);
            return false;
        }
        stbAjax('{:url("activity/editactivity")}', data, function (result) {
            //console.log(result);
            //$("#activityModel").modal('hide');
            toast('提示', result.msg, 1000);
            setTimeout('location.reload()', 500);
        });
    }
</script>